package com.feng.gaoerfu.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.feng.gaoerfu.R;
import com.feng.gaoerfu.bean.GolfHoleBean;

import java.util.List;

import static com.feng.gaoerfu.base.App.mContext;

public class ViewPagerAdapter extends PagerAdapter {

    private final List<GolfHoleBean> list;

    public ViewPagerAdapter(List<GolfHoleBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View inflate = View.inflate(mContext, R.layout.layout_view_page, null);
        TextView tvPar = (TextView) inflate.findViewById(R.id.tv_par);
        TextView tvNum = (TextView) inflate.findViewById(R.id.tv_num);
        ImageView ivBall = (ImageView) inflate.findViewById(R.id.iv_fqt);
        TextView tvHoleName = (TextView) inflate.findViewById(R.id.tv_hole_name);

        //            tvPar.setText(list.get(position).);
        //            tvNum.setText(list.get(position).num);
        //            ivBall.setImageResource(list.get(position).fqtColor);
        tvHoleName.setText(list.get(position).holeName);
        container.addView(inflate);
        return inflate;
    }
}